package com.zxl.yjb.activity.im;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.zxl.yjb.R;
import com.zxl.yjb.app.Const;
import com.zxl.yjb.base.BaseActivity;
import com.zxl.yjb.bean.JpushExtraBean;
import com.zxl.yjb.http.manager.DataManager;
import com.zxl.yjb.http.observer.ObserverOnNextListener;
import com.zxl.yjb.http.observer.ProgressObserver;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DialogActivity1 extends BaseActivity {


    @BindView(R.id.tv_orderdetail_id)
    TextView tvOrderdetailId;
    @BindView(R.id.tv_order_type)
    TextView tvOrderType;
    @BindView(R.id.tv_order_endtime)
    TextView tvOrderEndtime;
    private JpushExtraBean messge;
    private String orderid;


    @Override
    protected void initView() {
        orderid = messge.getResponse_id();
        tvOrderdetailId.setText(orderid);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog1);
        ButterKnife.bind(this);

        String stringExtra = getIntent().getStringExtra(Const.KEY_EXTRAS);
        if (!TextUtils.isEmpty(stringExtra)) {
            Gson gson = new Gson();
           messge = gson.fromJson(stringExtra, JpushExtraBean.class);
            initView();
        }

    }


    @OnClick({R.id.tv_cancle, R.id.tv_ok})
    public void onViewClicked(View view) {
        Map<String, String> map = new HashMap<>();
        map.put("order_id", orderid);
        switch (view.getId()) {
            case R.id.tv_cancle://拒绝
                map.put("accept1refuse2","2");
                accept(map);
                break;
            case R.id.tv_ok://接单
                map.put("accept1refuse2","1");
                accept(map);
//                startActivity(new Intent(getApplicationContext(), MainActivity.class).putExtra("refrensh", "refrensh"));
                break;
        }
    }

    /**
     * 接单
     */
    private void accept(Map<String,String> map) {
        if (TextUtils.isEmpty(orderid)) {
            return;
        }
        finish();
        DataManager dataManager = new DataManager();
        dataManager.accept(new ProgressObserver<Object>(new ObserverOnNextListener<Object>() {
            @Override
            public void onNext(Object o) {

            }
        }, this){
            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        },map);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_BACK){
        }
        return true;
    }
}
